function P=CF_step_player(G,P,k)
global Board
x=0;y=0;
while x<1|x>G.N_Size|y<1|y>G.N_Size|Board(x,y)>0,
    [x,y,but]=ginput(1);
    x=floor(x+0.5);
    y=floor(y+0.5);
    if but~=1,
        choice=menu('Are you sure to terminate this game?',{'OK','Cancel'});
        if choice==1,
            P.is_gameover=1;
            return;
        end;
    end;
    if x<1|x>G.N_Size|y<1|y>G.N_Size,
        menu('Warning: You cannot click outside the board! Please rechoose your piece!',{'OK'});
    elseif Board(x,y)>0,
        menu('Warning: This position is occupied! Please rechoose your piece!',{'OK'});
    end;
end;
P.pos=[x,y];
P.Vars=P.pos;
Board(x,y)=k;
P.is_gameover=chk_gameover(x,y,G.N_Size)
if P.is_gameover>0,
    show_piece(x,y,k);
    P.info=newinfo(['GAME OVER!'],'HorizontalAlignment','center');
    drawinfo(P.info);
end;


function res=chk_gameover(x,y,N)
d=[
1,0;
-1,0;
0,1;
0,-1;
1,1;
-1,-1;
1,-1;
-1,1
]
r=zeros(1,8);
for m=1:8,
    r(m)=count_num(x,y,N,d(m,:));
end;
res= r(1)+r(2)==6 | r(3)+r(4)==6 | r(5)+r(6)==6 | r(7)+r(8)==6;

function cnt=count_num(x,y,N,dd)
global Board
xx=x;yy=y;bb=Board(x,y);cnt=0;
while (xx>0) & logical(xx<=N) & (yy>0) & (yy<=N) & (Board(xx,yy)==bb),
    cnt=cnt+1;
    xx=xx+dd(1);
    yy=yy+dd(2);
end;
